
Partial Class Modules_Questionnaires_Controls_cfgText
    Inherits System.Web.UI.UserControl
    Implements DotNetPM.Business.Questionnaire.UserControls.IConfigUC

    Private _AnswerType As Integer

    Public Property AnswerType() As Integer Implements DotNetPM.Business.Questionnaire.UserControls.IConfigUC.AnswerType
        Get
            Return _AnswerType
        End Get
        Set(ByVal value As Integer)
            _AnswerType = value
        End Set
    End Property

    Public Property Config() As String Implements DotNetPM.Business.Questionnaire.UserControls.IConfigUC.Config
        Get
            Dim build As New StringBuilder
            build.Append(_AnswerType)
            build.Append("||" & rRequired.SelectedIndex)
            build.Append("||" & IIf(txtMinSize.Text = "N/A", String.Empty, txtMinSize.Text))
            build.Append("||" & txtMaxSize.Text)
            build.Append("||" & ddlExpressions.SelectedIndex)
            If ddlExpressions.SelectedIndex = 1 Then
                build.Append("||" & txtExpression.Text)
            End If
            Return build.ToString
        End Get
        Set(ByVal value As String)
            Dim val As String() = Split(value, "||")
            _AnswerType = val(0)
            Integer.TryParse(val(1), rRequired.SelectedIndex)
            txtMinSize.Text = val(2)
            txtMaxSize.Text = val(3)
            Integer.TryParse(val(4), ddlExpressions.SelectedIndex)
            If val(4) = "1" Then
                hfExpression.Value = val(5)
            End If
        End Set
    End Property

    Public Sub Reset() Implements DotNetPM.Business.Questionnaire.UserControls.IConfigUC.Reset
        ' Clear values
        txtMinSize.Text = ""
        txtMaxSize.Text = ""
        txtExpression.Text = ""
        ddlExpressions.SelectedIndex = 0
        rRequired.SelectedIndex = 0
    End Sub

    Protected Sub ddlExpressions_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlExpressions.PreRender
        IndexChanged()
        'Response.Write("ddlExpressions_PreRender: " & ddlExpressions.SelectedIndex & "<br/>")
    End Sub

    Private Sub IndexChanged()
        If ddlExpressions.SelectedIndex = 0 Then
            'none
            txtMinSize.Enabled = True
            txtMaxSize.Enabled = True
            rangeMin.Visible = True
            compMaxMin.Visible = True
            reqMax.Visible = False
            txtExpression.Enabled = False
            hfExpression.Value = ""
            trExpression.Visible = False
        Else
            txtMinSize.Text = "N/A"
            txtMinSize.Enabled = False
            rangeMin.Visible = False
            compMaxMin.Visible = False
            reqMax.Visible = True
            trExpression.Visible = True
            If ddlExpressions.SelectedIndex = 1 Then
                'custom
                txtExpression.Enabled = True
            Else
                txtExpression.Enabled = False
                hfExpression.Value = ddlExpressions.SelectedItem.Value
            End If
        End If
        txtExpression.Text = hfExpression.Value
    End Sub

End Class
